package org.rooster.manager;

import org.rooster.dbmanager.repository.RoosterRepository;
import org.rooster.schedule.ResourceCapability;

import java.util.Iterator;
import java.util.Set;

/**
 * Created by IntelliJ IDEA.
 * User: manorama
 * Date: 8/10/12
 * Time: 8:05 PM
 * To change this template use File | Settings | File Templates.
 */
public class ResourceCapabilitiesTracker {

    //this array stores each employees capability of working in each section
    //1-if the employee is capable of working in the particular section
    //0-if not capable

    private  int[][] sectionCapabilities;
    private static ResourceCapabilitiesTracker instance;

    public int getEmployeeCapability(int employeeId, int sectionNo) {
        return sectionCapabilities[employeeId-1][sectionNo];
    }

    private ResourceCapabilitiesTracker() {
        sectionCapabilities = new int[ResourceManager.TOTAL_NO_OF_EMPLOYEES][TaskManager.NO_OF_SECTIONS];
        initializeCapabilitiesTracker();
    }

    public static ResourceCapabilitiesTracker getInstance() {
        if(instance == null) {
            instance = new ResourceCapabilitiesTracker();
        }
        return instance;
    }

    private void initializeCapabilitiesTracker() {
        Set<ResourceCapability> employeeCapabilitySet = RoosterRepository.getInstance().getResourceCapabilities();

        //todo retrieve the number of tasks using the count SQl statements

        Iterator iterator = employeeCapabilitySet.iterator();
        ResourceCapability employeeCapability;
        while (iterator.hasNext()) {
            employeeCapability = (ResourceCapability) iterator.next();
            sectionCapabilities[employeeCapability.getResourceId()]
                    [employeeCapability.getTaskId()]= employeeCapability.getCapability();
        }
    }

}
